package com.sg.hms.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sg.hms.Service.ShenqingshenpiService;
import com.sg.hms.ServiceImpl.ShenqingshenpiServiceImpl;
/**
 * 
 * @author 廖彦
 *
 */
public class ShenpishenqingController extends HttpServlet{
	ShenqingshenpiService shenpi = new ShenqingshenpiServiceImpl();
     @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	// TODO Auto-generated method stub
    	doPost(req, resp);
    }
     @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	// TODO Auto-generated method stub
    	 req.setCharacterEncoding("UTF-8");
    	 resp.setCharacterEncoding("UTF-8");
    	 PrintWriter pw = resp.getWriter();
    	 //获得审批的状态："通过"或者"未通过"
    	 String state = req.getParameter("dept");
    	 //获得申请的ID
    	 int maId = Integer.parseInt(req.getParameter("maId"));
    	 //获得审批日期
    	 String approveDate = req.getParameter("approveDate");
    	 int flag = shenpi.updateshenqing(maId, state, approveDate);
    	 if (flag==1) {
			if (state.equals("已通过")) {
				pw.write("1");
			} else {
                pw.write("0");
			}
		} else {
            pw.write("-1");
		}
    	 
    }
}
